import { CommentEntity } from 'src/api/comment/entities/comment.entity';
import { SharedEntity } from 'src/api/shared/entities/shared.entity';
import { Column, Entity, OneToMany } from 'typeorm';
import { ArticleLikeEntity } from './article.like.entity';
import { ArticleTagEntity } from './article.tag.entity';

@Entity('article')
export class ArticleEntity extends SharedEntity {
  @Column({
    type: 'varchar',
    length: 200,
    nullable: true,
    name: 'title',
    comment: '标题',
  })
  title: string;

  @Column({
    type: 'varchar',
    nullable: false,
    name: 'content',
    comment: '内容',
  })
  content: string;

  @Column({
    type: 'varchar',
    name: 'author',
    comment: '作者',
  })
  author: string;

  @Column({
    type: 'varchar',
    nullable: false,
    name: 'user_id',
    comment: '关联用户表的ID',
  })
  userId: string;

  // 对应的文章tag id
  @OneToMany(() => ArticleTagEntity, (articleTag) => articleTag.article, {
    cascade: true,
  })
  tags: ArticleTagEntity[];

  @Column({
    type: 'varchar',
    name: 'picture',
    nullable: true,
    comment: '内容图片',
  })
  picture: string;

  // 对应为评论
  @OneToMany(() => CommentEntity, (articleComment) => articleComment.article)
  articleComments: CommentEntity[];

  // 一个文章对应多个点赞
  @OneToMany(() => ArticleLikeEntity, (articleLike) => articleLike.article)
  likes: ArticleLikeEntity[];
}
